﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KCommon
{
    public class Param
    {
        public Dictionary<string, string> _dicParam = new Dictionary<string, string>();

        private List<string> _lstKey = new List<string>();

        public Param()
        {
            
        }

        public Param(string paramString)
        {
            _dicParam.Clear();
            InputFromString(paramString);
        }

        public void Add(string key, string value)
        {
            string value2 = "";
            if (!_dicParam.TryGetValue(key, out value2))
            {
                _dicParam.Add(key, value);
                _lstKey.Add(key);
            }
            else
            {
                _dicParam[key] = value;
            }
        }

        public string Get(string key)
        {
            if (null==_dicParam)
            {
                return "";
            }
            string value = "";
            if (_dicParam.TryGetValue(key, out value))
            {
                return value;
            }
            else
            {
                return "";
            }
        }

        public void InputFromString(string info)
        {
            //_dicParam.Clear();
            _dicParam = DictionaryCovert.StringToDictionary(info);
        }

        public override string ToString()
        {
            string info = DictionaryCovert.DictionaryToString(_dicParam);
           // _dicParam.Clear();
            return info;
        }
    }
}
